package com.drojian;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

public class GlideRecyclerViewAdapter extends RecyclerView.Adapter<GlideRecyclerViewAdapter.ViewHolder> {
    private Context mContext;
    String[] mData = new String[]{
            "https://www.wanandroid.com/blogimgs/6c90079f-8062-4edc-aca3-f80718c9bec6.png"
            , "https://www.wanandroid.com/blogimgs/6c90079f-8062-4edc-aca3-f80718c9bec6.png"
            , "https://www.wanandroid.com/blogimgs/6c90079f-8062-4edc-aca3-f80718c9bec6.png"
            , "https://www.wanandroid.com/blogimgs/6c90079f-8062-4edc-aca3-f80718c9bec6.png"
            , "https://www.wanandroid.com/blogimgs/6c90079f-8062-4edc-aca3-f80718c9bec6.png"
            , "https://www.wanandroid.com/blogimgs/6c90079f-8062-4edc-aca3-f80718c9bec6.png"
            , "https://www.wanandroid.com/blogimgs/6c90079f-8062-4edc-aca3-f80718c9bec6.png"
            , "https://www.wanandroid.com/blogimgs/6c90079f-8062-4edc-aca3-f80718c9bec6.png"
            , "https://www.wanandroid.com/blogimgs/6c90079f-8062-4edc-aca3-f80718c9bec6.png"
            , "https://www.wanandroid.com/blogimgs/6c90079f-8062-4edc-aca3-f80718c9bec6.png"
            , "https://www.wanandroid.com/blogimgs/6c90079f-8062-4edc-aca3-f80718c9bec6.png"
    };

    public GlideRecyclerViewAdapter(Context context) {
        mContext = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(mContext, R.layout.item_glide, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Glide.with(mContext)
                .load(mData[position])
                //.animate()动画
                .centerCrop()
                .fitCenter()
                .into(holder.imageView);



    }

    @Override
    public int getItemCount() {
        return mData.length;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView imageView;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.image);
        }
    }
}
